package com.heima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.mapper.SkuMapper;
import com.heima.pojo.dto.SkuAddDto;
import com.heima.pojo.dto.SkuSearchDto;
import com.heima.pojo.entity.Sku;
import com.heima.pojo.vo.PageResponseVo;
import com.heima.pojo.vo.SkuVO;
import com.heima.service.SkuService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 商品管理接口
 */
@RestController
@RequestMapping("/api/vm-service/sku")
public class SkuController {

    @Autowired
    private SkuService skuService;

    @Autowired
    private SkuMapper skuMapper;

    //分页查询商品数据 根据商品名称条件查询
    @GetMapping("/search")
    public PageResponseVo<SkuVO> searchSku(SkuSearchDto dto) {
        return skuService.searchSku(dto.getPageIndex(), dto.getPageSize(), dto.getSkuName());
    }

    //新增商品
    @PostMapping
    public boolean addSku(@RequestBody SkuAddDto skuAddDto) {
     return   skuService.addSku(skuAddDto);
    }
    //根据商品id修改商品
    @PutMapping("/{skuId}")
    public boolean updateSku(@PathVariable Long skuId, @RequestBody SkuAddDto skuAddDto) {
        return  skuService.updateById(skuId, skuAddDto);

    }
}
